//
// Created by snake on 2022/11/8.
//

// #ifndef AOS_ARG_H
// #define AOS_ARG_H
#pragma once

#include <string>
#include <getopt.h>

using namespace std;

struct Args {
    bool all = false;
    bool ignore_blank = false;
    bool recursive = false;
    int thread = 1;
    // 默认 ""
    string suffix;
};

/**
 * 命令行参数信息->struct
 * @param argc 参数数
 * @param argv 参数数组
 * @param options 短参数配置
 * @param long_options 长参数配置
 * @return 结构体
 */
Args parse_serv_args(int argc, char *argv[]) {
    option long_options[] = {
            {"all",    no_argument,       nullptr, 'A'},
            {"suffix", required_argument, nullptr, 's'},
            {"thread", required_argument, nullptr, 't'},
    };
    int opt, opt_idx;
    Args args;
    while ((opt = getopt_long(argc,
                              argv,
                              "Abrs:t:",
                              long_options,
                              &opt_idx)) != -1) {
        switch (opt) {
            case 'A':
                args.all = true;
                break;
            case 'b':
                args.ignore_blank = true;
                break;
            case 'r':
                args.recursive = true;
                break;
            case 's':
                args.suffix = optarg;
                break;
            case 't':
                args.thread = strtol(optarg, nullptr, 10);
            default:
                break;
        }
    }
    return args;
}


// #endif //AOS_ARG_H
